#!/usr/bin/env python

'''
Created on 2009-7-28

@author: crackcell
'''

import random
from mywork.network.hessianlib import Hessian
import mywork.network.http

def generate_random_data():
    "generate random data for file"
    len = random.randint(1, 1000)
    buff = ''
    for i in range(len):
        buff = buff + ''.join([chr(random.randrange(256)) for i in range(102)])
    return buff

def test_upload(file_count):
    "test upload"
    file_map = {}
    for i in range(file_count):
        file_map["file" + str(i)] = "1234567890"#generate_random_data()
    
    for file_name in file_map:
        url = "http://localhost:8006/upload/?filename=" + file_name
        respon = mywork.network.http.post(url, file_map[file_name], True)
        print "** response %s: %s" % (file_name, respon)
        
def test_download(file_name):
    "test download"
    url = "http://localhost:8006/upload/?filename=" + file_name
    respon = mywork.network.http.get(url, True)
    print "** response %s: %s" % (file_name, respon)

def test_metadata(file_name):
    "test metadata"
    url = "http://localhost:8006/metadata/?filename=" + file_name
    respon = mywork.network.http.get(url, True)
    print "** response %s: %s" % (file_name, respon)

def test_delete(file_name):
    "test delete"
    url = "http://localhost:8006/delete/?filename=" + file_name
    respon = mywork.network.http.get(url, True)
    print "** response %s: %s" % (file_name, respon)    

def test_monitor():
    proxy = Hessian("http://localhost:8008/manage", "none", "none")

    try:
        print proxy
#        info_map = proxy.call("sendSignal", {"brickName":"debug", "type":"TEST"})
        info_map = proxy.call("sendRemoteSignal", {"url":"http://localhost:8007/manage", "brickName":"debug", "type":"TEST"})
        print "map:"
        print info_map
    except:
        print "ERROR"

if "__main__" == __name__:
    test_monitor()
        
